/**
 * Created by Amaris on 2016/10/9.
 */

var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * @type {void|*}
 */
module.exports = Waterline.Collection.extend({
    identity: 'stock_channel',
    tableName: 'tb_stock_channel',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function () {
                return uuid.v4();
            }
        },
        stockId: {
            type: 'string',
            required: true,
            columnName: 'stockId',
            model:'dic_stock'
        },
        stockGroupId: {
            type: 'string',
            columnName: 'stockGroupId',
            model: 'stock_group'
        },
        level: {
            type: 'string',
            columnName: 'level',
        },
        industry: {
            type: 'string',
            columnName: 'industry',
            model: 'industry'
        },
        channelType: {
            type: 'string',
            required: true,
            columnName: 'channelType',
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createUid',
            model: 'user'
        },
        updatedAt: {
            type: 'string',
            columnName: 'updatedAt'
        },
        cost:{
            type: 'float',
            columnName: 'cost',
        },
        /**
         * 持仓量
         */
        positionNum: {
            type: 'string',
            columnName: 'positionNum',
        },
        // /**
        //  *股票预估集合
        //  */
        // stockEstimates: {
        //     collection: 'stock_estimate',
        //     via: 'stockChannelId'
        // },
        /**
         *是否删除，1表示正常默认为1，0表示删除
         */
        enable: {
            type: 'int',
            columnName: 'enable',
            defaultsTo:'1'
        },
        createdAt: {
            type: 'string',
            required: true,
            columnName: 'createdAt'
        },
        toJSON: function () {
            var obj = this.toObject();
            obj.createdAt = moment(obj.createdAt).format('YYYY/MM/DD hh:mm');
            obj.updatedAt = moment(obj.updatedAt).format('YYYY/MM/DD hh:mm');
            return obj;
        }

    }
});
